import delimited "$dir/Model/estimates_1.csv", clear
xpose, clear
ren v1 est_all
gen n = _n
tempfile est_all
save `est_all'


import delimited "$dir/Model/estimates_2.csv", clear
xpose, clear
ren v1 est_white
gen n = _n
tempfile est_white
save `est_white'

import delimited "$dir/Model/estimates_3.csv", clear
xpose, clear
ren v1 est_black
gen n = _n
tempfile est_black
save `est_black'



import delimited "$dir/Model/ses_1.csv", clear
xpose, clear
replace v1 = abs(v1)
replace v1 = sqrt(v1)
gen n = _n
ren v1 se_all
tempfile se_all
save `se_all'


//standard errors
import delimited "$dir/Model/ses_2.csv", clear
xpose, clear
replace v1 = abs(v1)
replace v1 = sqrt(v1)
gen n = _n
ren v1 se_w
tempfile se_w
save `se_w'


//standard errors
import delimited "$dir/Model/ses_3.csv", clear
xpose, clear
replace v1 = abs(v1)
replace v1 = sqrt(v1)
gen n = _n
ren v1 se_black







merge 1:1 n using `est_all', keep(match) nogen
merge 1:1 n using `est_white', keep(match) nogen
merge 1:1 n using `est_black', keep(match) nogen
merge 1:1 n using `se_w', keep(match) nogen
merge 1:1 n using `se_all', keep(match) nogen


drop n

order est_all se_all est_white se_w est_black se_black

ds
foreach var in `r(varlist)'{
		replace `var' = round(`var', 0.001)
}




gen order = .
replace order = 1 in 31
replace order = 2 in 33
replace order = 3 in 32
replace order = 4 in 34
replace order = 5 in 36
replace order = 6 in 35
replace order = 7 in 1
replace order = 8 in 2
replace order = 9 in 3
replace order = 10 in 4
replace order = 11 in 5
replace order = 12 in 6
replace order = 13 in 7
replace order = 14 in 8
replace order = 15 in 9
replace order = 16 in 24
replace order = 17 in 28
replace order = 18 in 29
replace order = 19 in 30
replace order = 20 in 10
replace order = 21 in 11
replace order = 22 in 12
replace order = 23 in 25
replace order = 24 in 13
replace order = 25 in 14
replace order = 26 in 15
replace order = 27 in 16
replace order = 28 in 26
replace order = 29 in 27
replace order = 30 in 17
replace order = 31 in 18
replace order = 32 in 19
replace order = 33 in 20
replace order = 34 in 21
replace order = 35 in 22
replace order = 36 in 23
replace order = 37 in 37
replace order = 38 in 38
replace order = 39 in 39
replace order = 40 in 40
replace order = 41 in 41
replace order = 42 in 42
replace order = 43 in 43
replace order = 44 in 44
replace order = 45 in 45
replace order = 46 in 47
replace order = 47 in 46
replace order = 48 in 48
replace order = 49 in 49

sort order 
drop order 

//flip sign of fertility costs
replace est_all = est_all * -1  in 1
replace est_white = est_white * -1  in 1
replace est_black = est_black * -1  in 1

replace est_all = est_all * -1  in 2
replace est_white = est_white * -1  in 2
replace est_black = est_black * -1  in 2


replace est_all = est_all * -1  in 4
replace est_white = est_white * -1  in 4
replace est_black = est_black * -1  in 4


preserve
keep if _n<38
texsave using "$output/Table_9", replace
restore 

keep if _n>=38 
texsave using "$output/Table_A10", replace


//end of dofile
